//
//  TMNetwork.h
//  Pods
//
//  Created by LIJUN on 16/8/24.
//
//

#import <Foundation/Foundation.h>
#import "TMNetworkConfig.h"

typedef void (^AFConstructionBlock)(id<AFMultipartFormData> formData);

typedef void (^TMRequestNetErrorBlock)(NSError *error);
typedef void (^TMRequestProgressBlock)(NSProgress *progress);
typedef void (^TMRequestTokenExpireBlock)(id responseObject);
typedef void (^TMRequestSuccessBlock)(id responseObject);
typedef void (^TMRequestFailureBlock)(id responseObject);

typedef NS_ENUM (NSInteger, TMRequestSerializerType) {
    ERequestSerializerTypeHTTP = 0,
    ERequestSerializerTypeJSON
};
typedef NS_ENUM (NSInteger, TMResponseSerializerType) {
    EResponseSerializerTypeHTTP = 0,
    EResponseSerializerTypeJSON
};

@interface TMNetwork : NSObject

+ (TMNetwork *)sharedInstance;

- (void)cancelAllRequests;
- (void)cancelSessionTask:(NSURLSessionTask *)sessionTask;

- (NSURLSessionTask *)GET:(NSString *)path
             headerParams:(NSDictionary *)headerParams
              queryParams:(NSDictionary *)queryParams
               formParams:(id)formParams
                withToken:(BOOL)withToken
                    model:(Class)modelClass
                 progress:(TMRequestProgressBlock)progressBlock
                  success:(TMRequestSuccessBlock)successBlock
                  failure:(TMRequestFailureBlock)failureBlock;

- (NSURLSessionTask *)GET:(NSString *)path
             headerParams:(NSDictionary *)headerParams
              queryParams:(NSDictionary *)queryParams
               formParams:(id)formParams
                withToken:(BOOL)withToken
                    model:(Class)modelClass
                 progress:(TMRequestProgressBlock)progressBlock
                  success:(TMRequestSuccessBlock)successBlock
                  failure:(TMRequestFailureBlock)failureBlock
                 netError:(TMRequestNetErrorBlock)netErrorBlock
              tokenExpire:(TMRequestTokenExpireBlock)tokenExpireBlock;

- (NSURLSessionTask *)GET:(NSString *)path
    requestSerializerType:(TMRequestSerializerType)requestSerializerType
   responseSerializerType:(TMResponseSerializerType)responseSerializerType
             headerParams:(NSDictionary *)headerParams
              queryParams:(NSDictionary *)queryParams
               formParams:(id)formParams
                withToken:(BOOL)withToken
                    model:(Class)modelClass
                 progress:(TMRequestProgressBlock)progressBlock
                  success:(TMRequestSuccessBlock)successBlock
                  failure:(TMRequestFailureBlock)failureBlock
                 netError:(TMRequestNetErrorBlock)netErrorBlock
              tokenExpire:(TMRequestTokenExpireBlock)tokenExpireBlock;

- (NSURLSessionTask *)POST:(NSString *)path
              headerParams:(NSDictionary *)headerParams
               queryParams:(NSDictionary *)queryParams
                formParams:(id)formParams
                 withToken:(BOOL)withToken
                     model:(Class)modelClass
                  progress:(TMRequestProgressBlock)progressBlock
                   success:(TMRequestSuccessBlock)successBlock
                   failure:(TMRequestFailureBlock)failureBlock;

- (NSURLSessionTask *)POST:(NSString *)path
              headerParams:(NSDictionary *)headerParams
               queryParams:(NSDictionary *)queryParams
                formParams:(id)formParams
                 withToken:(BOOL)withToken
                     model:(Class)modelClass
                  progress:(TMRequestProgressBlock)progressBlock
                   success:(TMRequestSuccessBlock)successBlock
                   failure:(TMRequestFailureBlock)failureBlock
                  netError:(TMRequestNetErrorBlock)netErrorBlock
               tokenExpire:(TMRequestTokenExpireBlock)tokenExpireBlock;


- (NSURLSessionTask *)POSTWithJSONRequestSerialized:(NSString *)path
                                       headerParams:(NSDictionary *)headerParams
                                        queryParams:(NSDictionary *)queryParams
                                         formParams:(id)formParams
                                          withToken:(BOOL)withToken
                                              model:(Class)modelClass
                                           progress:(TMRequestProgressBlock)progressBlock
                                            success:(TMRequestSuccessBlock)successBlock
                                            failure:(TMRequestFailureBlock)failureBlock;

- (NSURLSessionTask *)POSTWithJSONRequestSerialized:(NSString *)path
                                       headerParams:(NSDictionary *)headerParams
                                        queryParams:(NSDictionary *)queryParams
                                         formParams:(id)formParams
                                          withToken:(BOOL)withToken
                                              model:(Class)modelClass
                                           progress:(TMRequestProgressBlock)progressBlock
                                            success:(TMRequestSuccessBlock)successBlock
                                            failure:(TMRequestFailureBlock)failureBlock
                                           netError:(TMRequestNetErrorBlock)netErrorBlock
                                        tokenExpire:(TMRequestTokenExpireBlock)tokenExpireBlock;

- (NSURLSessionTask *)POST:(NSString *)path
     requestSerializerType:(TMRequestSerializerType)requestSerializerType
    responseSerializerType:(TMResponseSerializerType)responseSerializerType
              headerParams:(NSDictionary *)headerParams
               queryParams:(NSDictionary *)queryParams
                formParams:(id)formParams
                 withToken:(BOOL)withToken
                     model:(Class)modelClass
                  progress:(TMRequestProgressBlock)progressBlock
                   success:(TMRequestSuccessBlock)successBlock
                   failure:(TMRequestFailureBlock)failureBlock
                  netError:(TMRequestNetErrorBlock)netErrorBlock
               tokenExpire:(TMRequestTokenExpireBlock)tokenExpireBlock;

- (NSURLSessionTask *)POST:(NSString *)path
              headerParams:(NSDictionary *)headerParams
               queryParams:(NSDictionary *)queryParams
                formParams:(id)formParams
                 withToken:(BOOL)withToken
 constructingBodyWithBlock:(AFConstructionBlock)constructingBlock
                     model:(Class)modelClass
                  progress:(TMRequestProgressBlock)progressBlock
                   success:(TMRequestSuccessBlock)successBlock
                   failure:(TMRequestFailureBlock)failureBlock;

- (NSURLSessionTask *)POST:(NSString *)path
              headerParams:(NSDictionary *)headerParams
               queryParams:(NSDictionary *)queryParams
                formParams:(id)formParams
                 withToken:(BOOL)withToken
 constructingBodyWithBlock:(AFConstructionBlock)constructingBlock
                     model:(Class)modelClass
                  progress:(TMRequestProgressBlock)progressBlock
                   success:(TMRequestSuccessBlock)successBlock
                   failure:(TMRequestFailureBlock)failureBlock
                  netError:(TMRequestNetErrorBlock)netErrorBlock
               tokenExpire:(TMRequestTokenExpireBlock)tokenExpireBlock;

- (NSURLSessionTask *)POST:(NSString *)path
     requestSerializerType:(TMRequestSerializerType)requestSerializerType
    responseSerializerType:(TMResponseSerializerType)responseSerializerType
              headerParams:(NSDictionary *)headerParams
               queryParams:(NSDictionary *)queryParams
                formParams:(id)formParams
                 withToken:(BOOL)withToken
 constructingBodyWithBlock:(AFConstructionBlock)constructingBlock
                     model:(Class)modelClass
                  progress:(TMRequestProgressBlock)progressBlock
                   success:(TMRequestSuccessBlock)successBlock
                   failure:(TMRequestFailureBlock)failureBlock
                  netError:(TMRequestNetErrorBlock)netErrorBlock
               tokenExpire:(TMRequestTokenExpireBlock)tokenExpireBlock;
@end
